package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZcUsers;
import com.ruoyi.system.service.IZcUsersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 租车用户Controller
 *
 * @author ruoyi
 * @date 2025-04-03
 */
@Controller
@RequestMapping("/system/zcusers")
public class ZcUsersController extends BaseController
{
    private String prefix = "system/zcusers";

    @Autowired
    private IZcUsersService zcUsersService;

    @RequiresPermissions("system:zcusers:view")
    @GetMapping()
    public String zcusers()
    {
        return prefix + "/zcusers";
    }

    /**
     * 查询租车用户列表
     */
    @RequiresPermissions("system:zcusers:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZcUsers zcUsers)
    {
        startPage();
        List<ZcUsers> list = zcUsersService.selectZcUsersList(zcUsers);
        return getDataTable(list);
    }

    /**
     * 导出租车用户列表
     */
    @RequiresPermissions("system:zcusers:export")
    @Log(title = "租车用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZcUsers zcUsers)
    {
        List<ZcUsers> list = zcUsersService.selectZcUsersList(zcUsers);
        ExcelUtil<ZcUsers> util = new ExcelUtil<ZcUsers>(ZcUsers.class);
        return util.exportExcel(list, "租车用户数据");
    }

    /**
     * 新增租车用户
     */
    @RequiresPermissions("system:zcusers:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存租车用户
     */
    @RequiresPermissions("system:zcusers:add")
    @Log(title = "租车用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZcUsers zcUsers)
    {
        return toAjax(zcUsersService.insertZcUsers(zcUsers));
    }

    /**
     * 修改租车用户
     */
    @RequiresPermissions("system:zcusers:edit")
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        ZcUsers zcUsers = zcUsersService.selectZcUsersByUserId(userId);
        mmap.put("zcUsers", zcUsers);
        return prefix + "/edit";
    }

    /**
     * 修改保存租车用户
     */
    @RequiresPermissions("system:zcusers:edit")
    @Log(title = "租车用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZcUsers zcUsers)
    {
        return toAjax(zcUsersService.updateZcUsers(zcUsers));
    }

    /**
     * 删除租车用户
     */
    @RequiresPermissions("system:zcusers:remove")
    @Log(title = "租车用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zcUsersService.deleteZcUsersByUserIds(ids));
    }
}
